<%@ tag import="static com.eischet.lookup.StringUtilities.escapeForHtml" %>
<%@ tag import="org.apache.lucene.document.Field" %>
<%@ tag import="java.util.List" %>
<%@ tag language="java" pageEncoding="utf-8" %>
<%@ attribute name="searchResult" type="com.eischet.lookup.web.SearchResult" %>
<%@ attribute name="link" type="java.lang.Boolean" required="true" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="lookup" %>

<% boolean indirect = true; %>

<% if (indirect) {
    if (link) {
        %><span class="rawlink"><a href="?do=w&amp;h=<%=searchResult.getField("handle")%>">index structure</a></span><%
    }
} else {
    if (link) { %>
        <span class="rawlink">
            <input type="button" class="rawlink" onclick="reveal('raw<%=searchResult.getField("handle")%>')" value="index structure">
        </span>
    <% } else { %>
        <div style="display:none" id="raw<%=searchResult.get("handle")%>">
            <div class="dump">
                <table class="data">
                    <tr>
                        <th>Key</th>
                        <th>#</th>
                        <th>Values</th>
                        <th>Tokenized</th>
                        <th>Indexed</th>
                    </tr>
                    <% int countFields = 0; %>
                    <% for (String fieldName: searchResult.getKeys()) {
                        List<Field> fields = searchResult.getFields(fieldName);
                        Field first = fields.get(0);
                    %>
                        <%
                            if ("all".equals(fieldName)) continue; // skip the "all" conglomerate field
                            ++countFields;
                        %>
                        <tr>
                            <td><%= escapeForHtml(fieldName) %></td>
                            <td><%= fields.size() %></td>
                            <td>
                                <% for (Field f: fields) { %>
                                    <%= escapeForHtml(f.stringValue()) %>
                                <br>
                                <% } %>
                            </td>
                            <td>
                                <%= first.isTokenized() %>
                            </td>
                            <td>
                                <%= first.isIndexed() %>
                            </td>
                        </tr>
                    <% } %>
                    <% if (countFields == 0) { %>
                        <tr>
                            <td colspan="5" class="empty">No data found!</td>
                        </tr>
                    <% } %>
                </table>
            </div>
        </div>
    <% } %>
<% } %>
